package com.morphiastic;

import java.io.IOException;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.IdentityHashMap;

import org.elasticsearch.common.xcontent.XContentBuilder;



/**
 * 
 * A field bridge allowing us to customize how the field is written to the index
 * If a fieldBridge is declared inside a StandardIndexedField or a IndexedEmbeddedField
 * 
 * @author Alex
 *
 */
public abstract class IndexedFieldBridge {

	protected String name = "";
	
	protected HashMap<String, String> params = new HashMap<String, String>();
	
	private Class<?> clazz;
	
	/**
	 * see ElastiFieldBridge fullyOverrideDefault
	 * 
	 * defaults to false
	 * 
	 * should be set in the concrete implementation's constructor 
	 * 
	 * OR the fullyOverridesDefault() method can be overriden in the impl
	 * 
	 */
	protected boolean fullyOverrideDefault = false;
	
	public boolean fullyOverridesDefault(){
		return fullyOverrideDefault;
	}
	
	public HashMap<String, String> getParams() {
		return params;
	}
	
	/**
	 * Internal init method 
	 */
	protected final void _init(String name, Class<?> clazz, boolean fullyOverrideDefault, HashMap<String, String> params){
		 this.name = name;
		 this.clazz = clazz;
		 this.fullyOverrideDefault = fullyOverrideDefault;
		 this.params = params;
	}
	
	
	public String getName() {
		return name;
	}
	
	/**
	 *  Method automatically called by framework in which we can perform post instantiation initialization;
	 * 
	 *  The user can choose to override this method if needed or just ignore it (leave empty)
	 *  
	 *  The ElasticStore instance ios provided for easy navigation
	 *  
	 */
	public abstract void init(ElasticStore es, HashMap<?, ?> params);
	
	
	
	
	public abstract XContentBuilder writeIndexedField(XContentBuilder mappingBuilder , String fieldName,
											 Object o, ElasticStore es, 
											 Integer maxCircularRefDepth, IdentityHashMap<AccessibleObject, 
											 Integer> known )throws IOException ;
	
	
	
	
	public abstract void addIndexFieldSettings(XContentBuilder mappingBuilder) throws IOException ;




	public abstract void addFieldSettingsMap(HashMap<String, Object> props);
	
	
	
	
	
	
	
}
